/*
 * $Id: SimpleTestCase.java 56 2010-01-23 14:49:04Z aaron.day $
 */
package org.crazydays.gameplan.test;


import java.io.File;

import junit.framework.TestCase;

/**
 * 
 */
public class SimpleTestCase
    extends TestCase
{
    /** sandbox */
    protected File sandbox;

    /**
     * Cleanup sandbox.
     * 
     * @see junit.framework.TestCase#tearDown()
     */
    public void tearDown()
    {
        if (sandbox != null) {
            delete(sandbox);
        }
    }

    /**
     * Delete file or directory.
     * 
     * @param file File
     */
    protected void delete(File file)
    {
        assertNotNull("file == null", file);

        if (file.isDirectory()) {
            File[] children = file.listFiles();
            for (File child : children) {
                if (child.getName().equals(".") || child.getName().equals("..")) {
                    continue;
                }

                delete(child);
            }
        }

        assertTrue("Unable to delete file: " + file, file.delete());
    }

    /**
     * Get sandbox.
     * 
     * @return Sanbox
     */
    protected File getSandbox()
    {
        if (sandbox == null) {
            sandbox = new File(new File(".", "tmp"), getClass().getName());
            assertTrue("sandbox.mkdirs", sandbox.mkdirs());
        }

        return sandbox;
    }

    /**
     * Assert object is instance of clazz.
     * 
     * @param message Message
     * @param clazz Class
     * @param object Object
     */
    public void assertIsInstance(String message, Class<?> clazz, Object object)
    {
        assertTrue(message, clazz.isInstance(object));
    }

    /**
     * Assert call is unreachable.
     * 
     * @param message Message
     */
    public void assertUnreachable(String message)
    {
        fail(message);
    }
}
